﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace User.API.Data.Mapping
{
    public class UserTagMap
        : IEntityTypeConfiguration<UserTag>
    {
        public void Configure(EntityTypeBuilder<UserTag> builder)
        {
            //Table.
            builder.ToTable("UserTag");

            //Key.
            builder.HasKey("AppUserId", "Tag");

            //Property.
            builder.Property(t => t.Tag)
                .HasColumnName("Tag")
                .HasMaxLength(36)
                .IsUnicode(true)
                .IsRequired();
            builder.Property(t => t.CreateTime)
               .HasColumnName("CreateTime")
               .IsRequired();
            //Relation.
            builder.HasOne(t => t.AppUser)
                .WithMany(t => t.Tags)
                .HasForeignKey(t=>t.AppUserId);
        }
    }
}
